home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / haziran / 19 / setup.exe / data.z / pbc_diag.c < prev    next >
C/C++ Source or Header  |  2001-04-11  |  22KB  |  632 lines

  1. ////////////////////////////////////////////////////////////////
  2. // File - PBC_DIAG.C
  3. //
  4. // o A simple diagnostics program that lets you access the
  5. //   V3 PBC registers and local memory. 
  6. // o This program is meant to be used as an example for using the
  7. //   PBCLIB.H API,LIB you may use it as a skeleton for your driver,
  8. //   or 'cut & paste' parts of it into your device driver code.
  9. // 
  10. ////////////////////////////////////////////////////////////////
  11.  
  12. #include "../../include/windrvr.h"
  13. #include "../lib/pbclib.h"
  14. #include "../../samples/shared/pci_diag_lib.h"
  15. #include <stdio.h>
  16.  
  17. // input of command from user
  18. static char line[256];
  19.  
  20. void V3_EditReg(V3PBCHANDLE hV3)
  21. {
  22.     struct 
  23.     {
  24.         CHAR *name;
  25.         DWORD dwOffset;
  26.         DWORD dwVal;
  27.     } fields[40];
  28.  
  29.     int cmd;
  30.     int i;
  31.     int field_count;
  32.  
  33.     i = 0;
  34.     fields[i].name = "PCI_DEVICE_VENDOR  "; fields[i++].dwOffset = 0x00;
  35.     fields[i].name = "PCI_STAT_CMD       "; fields[i++].dwOffset = 0x04;
  36.     fields[i].name = "PCI_CC_REV         "; fields[i++].dwOffset = 0x08;
  37.     fields[i].name = "PCI_HDR_CFG        "; fields[i++].dwOffset = 0x0c;
  38.     fields[i].name = "PCI_IO_BASE        "; fields[i++].dwOffset = 0x10;
  39.     fields[i].name = "PCI_BASE0          "; fields[i++].dwOffset = 0x14;
  40.     fields[i].name = "PCI_BASE1          "; fields[i++].dwOffset = 0x18;
  41.     fields[i].name = "PCI_SUB_ID_VENDOR  "; fields[i++].dwOffset = 0x2c;
  42.     fields[i].name = "PCI_ROM            "; fields[i++].dwOffset = 0x30;
  43.     fields[i].name = "PCI_BPARM          "; fields[i++].dwOffset = 0x3c;
  44.     fields[i].name = "PCI_MAP0           "; fields[i++].dwOffset = 0x40;
  45.     fields[i].name = "PCI_MAP1           "; fields[i++].dwOffset = 0x44;
  46.     fields[i].name = "PCI_INT_STAT       "; fields[i++].dwOffset = 0x48;
  47.     fields[i].name = "PCI_INT_CFG        "; fields[i++].dwOffset = 0x4c;
  48.     fields[i].name = "LB_BASE0           "; fields[i++].dwOffset = 0x54;
  49.     fields[i].name = "LB_BASE1           "; fields[i++].dwOffset = 0x58;
  50.     fields[i].name = "LB_MAP0            "; fields[i++].dwOffset = 0x5c;
  51.     fields[i].name = "LB_MAP1            "; fields[i++].dwOffset = 0x60;
  52.     fields[i].name = "LB_IO_BASE         "; fields[i++].dwOffset = 0x6c;
  53.     fields[i].name = "FIFO_PRIORITY_CFG  "; fields[i++].dwOffset = 0x70;
  54.     fields[i].name = "LB_IMASK_ISTAT_STAT"; fields[i++].dwOffset = 0x74;
  55.     fields[i].name = "LB_CFG_SYSTEM      "; fields[i++].dwOffset = 0x78;
  56.     fields[i].name = "DMA_PCI_ADDR0      "; fields[i++].dwOffset = 0x80;
  57.     fields[i].name = "DMA_LOCAL_ADDR0    "; fields[i++].dwOffset = 0x84;
  58.     fields[i].name = "DMA_CRS0_LENGTH0   "; fields[i++].dwOffset = 0x88;
  59.     fields[i].name = "DMA_CTLB_ADDR0     "; fields[i++].dwOffset = 0x8c;
  60.     fields[i].name = "DMA_PCI_ADDR1      "; fields[i++].dwOffset = 0x90;
  61.     fields[i].name = "DMA_LOCAL_ADDR1    "; fields[i++].dwOffset = 0x94;
  62.     fields[i].name = "DMA_CRS0_LENGTH1   "; fields[i++].dwOffset = 0x98;
  63.     fields[i].name = "DMA_CTLB_ADDR1     "; fields[i++].dwOffset = 0x9c;
  64.     fields[i].name = "DMA_CTLB_ADDR1     "; fields[i++].dwOffset = 0x9c;
  65.     fields[i].name = "PCI_MAIL_IERD_IEWR "; fields[i++].dwOffset = 0xd0;
  66.     fields[i].name = "LB_MAIL_IERD_IEWR  "; fields[i++].dwOffset = 0xd4;
  67.     fields[i].name = "MAIL_RD_WR_STAT    "; fields[i++].dwOffset = 0xd8;
  68.     field_count = i;
  69.     do
  70.     {
  71.         int row;
  72.         int col;
  73.         int row_count = field_count/2 + field_count%2;
  74.  
  75.         printf ("\n");
  76.         printf ("Edit V3 PBC Rev%d registers\n", V3PBC_GetRevision(hV3));
  77.         printf ("--------------------------------\n");
  78.         for (row = 0; row<row_count; row++)
  79.         {
  80.             for (col = 0; col<=1; col++)
  81.             {
  82.                 if (col==0) i = row;
  83.                 else i = row + row_count;
  84.  
  85.                 if (i<field_count)
  86.                 {
  87.                     char buf[10];
  88.                     fields[i].dwVal = V3PBC_ReadRegDWord(hV3, fields[i].dwOffset);
  89.                     sprintf(buf, "%08x",fields[i].dwVal);
  90.                     printf ("%2d. %7s : %s    ",i+1, fields[i].name, buf);
  91.                 }
  92.                 if (col==1) printf ("\n");
  93.             }
  94.         }
  95.  
  96.         printf ("99. Back to main menu\n");
  97.         printf ("Choose register to write to, or 99 to exit: ");
  98.         cmd = 0;
  99.         fgets(line, sizeof(line), stdin);
  100.         sscanf (line, "%d",&cmd);
  101.         if (cmd>=1 && cmd <=34)
  102.         {
  103.             i = cmd-1;
  104.             printf ("Enter value to write to %s register ('X' to cancel): ",fields[i].name);
  105.             fgets(line, sizeof(line), stdin);
  106.             if (toupper (line[0])!='X')
  107.             {
  108.                 DWORD dwVal;
  109.                 dwVal = 0;
  110.                 sscanf (line,"%x",&dwVal);
  111.                 V3PBC_WriteRegDWord(hV3, fields[i].dwOffset, dwVal);
  112.             }
  113.         }
  114.     } while (cmd!=99);
  115. }
  116.  
  117. char *V3_GetAddrRangeName(V3PBC_ADDR addrSpace)
  118. {
  119.     return 
  120.         addrSpace==V3PBC_ADDR_IO_BASE ? "Configuration Register Space - (BAR0)" :
  121.         addrSpace==V3PBC_ADDR_BASE0 ? "Aperture 0 Space - (BAR1)" :
  122.         addrSpace==V3PBC_ADDR_BASE1 ? "Aperture 1 Space - (BAR2)" :
  123.         addrSpace==V3PBC_ADDR_ROM ? "ROM Address Space" : "Invalid";
  124. }
  125.  
  126. void V3_MailboxAccess(V3PBCHANDLE hV3)
  127. {
  128.     int cmd;
  129.     BYTE addr;
  130.     BYTE data;
  131.  
  132.     do
  133.     {
  134.         printf ("Access the board's mailbox data registers\n");
  135.         printf ("--------------------------------\n");
  136.         printf ("1. Read byte from mailbox data register on the board\n");
  137.         printf ("2. Write byte to the mailbox data register on the board\n");
  138.         printf ("99. Back to main menu\n");
  139.         printf ("\n");
  140.         printf ("Enter option: ");
  141.         cmd = 0;
  142.         fgets(line, sizeof(line), stdin);
  143.         sscanf (line, "%d",&cmd);
  144.         switch (cmd)
  145.         {
  146.         case 1:
  147.             printf ("Enter mailbox data register to read from (0-15): ");
  148.             fgets(line, sizeof(line), stdin);
  149.             sscanf (line, "%d", &addr);
  150.             if (addr <= 15)
  151.             {
  152.                 data = V3PBC_ReadRegByte(hV3, V3PBC_MAIL_DATA0 + addr); 
  153.                 printf ("Value read: %x\n", data);
  154.             }
  155.             else
  156.                 printf("Invalid range for mailbox data register\n");
  157.             
  158.             break;
  159.  
  160.         case 2:
  161.             printf ("Enter mailbox data register to write to (0-15): ");
  162.             fgets(line, sizeof(line), stdin);
  163.             sscanf (line, "%d", &addr);
  164.             if (addr <= 15)
  165.             {
  166.                 printf ("Enter data to write (0-ff): ");
  167.                 fgets(line, sizeof(line), stdin);
  168.                 sscanf (line, "%x",&data);
  169.                 V3PBC_WriteRegByte(hV3, V3PBC_MAIL_DATA0 + addr, data); 
  170.             }
  171.             else
  172.                 printf("Invalid range for mailbox data register\n");
  173.  
  174.             break;
  175.  
  176.         default:
  177.             break;
  178.         }
  179.     } while (cmd!=99);
  180. }
  181.  
  182. void V3_BoardAccess(V3PBCHANDLE hV3)
  183. {
  184.     int cmd;
  185.     DWORD addr, data, ad_mode;
  186.     ad_mode = V3PBC_MODE_DWORD;
  187.     if (!V3PBC_IsAddrSpaceActive(hV3, V3PBC_ADDR_BASE0))
  188.     {
  189.         printf ("BASE0 memory space not active!\n");
  190.         return;
  191.     }
  192.  
  193.     do
  194.     {
  195.         printf ("Access the board's local address ranges\n");
  196.         printf ("---------------------------------------\n");
  197.         printf ("(Access to invalid local address may hang the computer!)\n");
  198.         printf ("2. Toggle active mode: %s\n", 
  199.             ad_mode==V3PBC_MODE_BYTE ? "BYTE (8 bit)" :
  200.             ad_mode==V3PBC_MODE_WORD ? "WORD (16 bit)" : "DWORD (32 bit)");
  201.         printf ("3. Read from board\n");
  202.         printf ("4. Write to board\n");
  203.         printf ("99. Back to main menu\n");
  204.         printf ("\n");
  205.         printf ("Enter option: ");
  206.         cmd = 0;
  207.         fgets(line, sizeof(line), stdin);
  208.         sscanf (line, "%d",&cmd);
  209.         switch (cmd)
  210.         {
  211.         case 2:
  212.             ad_mode = (ad_mode + 1) % 3;
  213.             break;
  214.         case 3:
  215.             printf ("Enter local address to read from: ");
  216.             fgets(line, sizeof(line), stdin);
  217.             sscanf (line, "%x", &addr);
  218.             switch (ad_mode)
  219.             {
  220.             case V3PBC_MODE_BYTE:
  221.                 data = V3PBC_ReadByte(hV3, addr);
  222.                 break;
  223.             case V3PBC_MODE_WORD:
  224.                 data = V3PBC_ReadWord(hV3, addr);
  225.                 break;
  226.             case V3PBC_MODE_DWORD:
  227.                 data = V3PBC_ReadDWord(hV3, addr);
  228.                 break;
  229.             }
  230.             printf ("Value read: %x\n", data);
  231.             break;
  232.         case 4:
  233.             printf ("Enter local address to write to: ");
  234.             fgets(line, sizeof(line), stdin);
  235.             sscanf (line, "%x", &addr);
  236.             printf ("Enter data to write %s: ",
  237.                 ad_mode==V3PBC_MODE_BYTE ? "BYTE (8 bit)" :
  238.                 ad_mode==V3PBC_MODE_WORD ? "WORD (16 bit)" : "DWORD (32 bit)");
  239.             fgets(line, sizeof(line), stdin);
  240.             sscanf (line, "%x",&data);
  241.             switch (ad_mode)
  242.             {
  243.             case V3PBC_MODE_BYTE:
  244.                 V3PBC_WriteByte(hV3, addr, (BYTE) data);
  245.                 break;
  246.             case V3PBC_MODE_WORD:
  247.                 V3PBC_WriteWord(hV3, addr, (WORD) data);
  248.                 break;
  249.             case V3PBC_MODE_DWORD:
  250.                 V3PBC_WriteDWord(hV3, addr, data);
  251.                 break;
  252.             }
  253.             break;
  254.         }
  255.     } while (cmd!=99);
  256. }
  257.  
  258. void V3_BoardAccessSpaces(V3PBCHANDLE hV3)
  259. {
  260.     int cmd, cmd2, i;
  261.     DWORD addr, data;
  262.     V3PBC_ADDR ad_sp = V3PBC_ADDR_IO_BASE;
  263.     V3PBC_MODE ad_mode = V3PBC_MODE_DWORD;
  264.  
  265.     for (; ad_sp<=V3PBC_ADDR_ROM && !V3PBC_IsAddrSpaceActive(hV3, ad_sp); ad_sp++)
  266.     if (ad_sp>V3PBC_ADDR_ROM)
  267.     {
  268.         printf ("No active memory spaces on board!\n");
  269.         return;
  270.     }
  271.  
  272.     do
  273.     {
  274.         printf ("Access the board's memory ranges\n");
  275.         printf ("--------------------------------\n");
  276.         printf ("(Access to invalid local address may hang the computer!)\n");
  277.         printf ("1. Change active memory space: %s\n",V3_GetAddrRangeName(ad_sp));
  278.         printf ("2. Toggle active mode: %s\n", 
  279.             ad_mode==V3PBC_MODE_BYTE ? "BYTE (8 bit)" :
  280.             ad_mode==V3PBC_MODE_WORD ? "WORD (16 bit)" : "DWORD (32 bit)");
  281.         printf ("3. Read from board\n");
  282.         printf ("4. Write to board\n");
  283.         printf ("99. Back to main menu\n");
  284.         printf ("\n");
  285.         printf ("Enter option: ");
  286.         cmd = 0;
  287.         fgets(line, sizeof(line), stdin);
  288.         sscanf (line, "%d",&cmd);
  289.         switch (cmd)
  290.         {
  291.         case 1:
  292.             printf ("Choose memory space:\n");
  293.             printf ("--------------------\n");
  294.             for (i=V3PBC_ADDR_IO_BASE; i<=V3PBC_ADDR_ROM; i++)
  295.             {
  296.                 printf ("%d. %s", i, V3_GetAddrRangeName(i));
  297.                 if (V3PBC_IsAddrSpaceActive(hV3, i)) printf ("\n");
  298.                 else printf (" - space not active\n");
  299.             }
  300.             printf ("Enter option: ");
  301.             cmd2 = 99;
  302.             fgets(line, sizeof(line), stdin);
  303.             sscanf (line, "%d",&cmd2);
  304.             if (cmd2>=V3PBC_ADDR_IO_BASE && cmd2<=V3PBC_ADDR_ROM)
  305.             {
  306.                 int new_ad_sp = cmd2;
  307.                 if (V3PBC_IsAddrSpaceActive(hV3, new_ad_sp)) ad_sp = new_ad_sp;
  308.                 else printf ("Chosen space not active!\n");
  309.             }
  310.             break;
  311.         case 2:
  312.             ad_mode = (ad_mode + 1) % 3;
  313.             break;
  314.         case 3:
  315.             printf ("Enter offset to read from: ");
  316.             fgets(line, sizeof(line), stdin);
  317.             sscanf (line, "%x", &addr);
  318.             switch (ad_mode)
  319.             {
  320.             case V3PBC_MODE_BYTE:
  321.                 data = V3PBC_ReadSpaceByte(hV3, ad_sp, addr);
  322.                 break;
  323.             case V3PBC_MODE_WORD:
  324.                 data = V3PBC_ReadSpaceWord(hV3, ad_sp, addr);
  325.                 break;
  326.             case V3PBC_MODE_DWORD:
  327.                 data = V3PBC_ReadSpaceDWord(hV3, ad_sp, addr);
  328.                 break;
  329.             }
  330.             printf ("Value read: %x\n", data);
  331.             break;
  332.         case 4:
  333.             printf ("Enter offset to write to: ");
  334.             fgets(line, sizeof(line), stdin);
  335.             sscanf (line, "%x", &addr);
  336.             printf ("Enter data to write %s: ",
  337.                 ad_mode==V3PBC_MODE_BYTE ? "BYTE (8 bit)" :
  338.                 ad_mode==V3PBC_MODE_WORD ? "WORD (16 bit)" : "DWORD (32 bit)");
  339.             fgets(line, sizeof(line), stdin);
  340.             sscanf (line, "%x",&data);
  341.             switch (ad_mode)
  342.             {
  343.             case V3PBC_MODE_BYTE:
  344.                 V3PBC_WriteSpaceByte(hV3, ad_sp, addr, (BYTE) data);
  345.                 break;
  346.             case V3PBC_MODE_WORD:
  347.                 V3PBC_WriteSpaceWord(hV3, ad_sp, addr, (WORD) data);
  348.                 break;
  349.             case V3PBC_MODE_DWORD:
  350.                 V3PBC_WriteSpaceDWord(hV3, ad_sp, addr, data);
  351.                 break;
  352.             }
  353.             break;
  354.         }
  355.     } while (cmd!=99);
  356. }
  357.  
  358. void WINAPI V3_IntHandlerRoutine(V3PBCHANDLE hV3, V3PBC_INT_RESULT *intResult)
  359. {
  360.     printf ("Got interrupt number %d\n", intResult->dwCounter);
  361. }
  362.  
  363. void V3_EnableDisableInterrupts(V3PBCHANDLE hV3)
  364. {
  365.     int cmd;
  366.  
  367.     printf ("WARNING!!!\n");
  368.     printf ("----------\n");
  369.     printf ("Your hardware has level sensitive interrupts.\n");
  370.     printf ("You must modify the source code of V3PBC_IntEnable(), in the file pbclib.c,\n");
  371.     printf ("to acknowledge the interrupt before enabling interrupts.\n");
  372.     printf ("Without this modification, your PC will HANG upon interrupt!\n");
  373.  
  374.     do
  375.     {
  376.         printf ("Enable / Disable interrupts\n");
  377.         printf ("---------------------------\n");
  378.         printf ("1. %s interrupts\n", V3PBC_IntIsEnabled(hV3) ? "Disable" : "Enable");
  379.         printf ("99. Back to main menu\n");
  380.         printf ("\n");
  381.         printf ("Enter option: ");
  382.         cmd = 0;
  383.         fgets(line, sizeof(line), stdin);
  384.         sscanf (line, "%d",&cmd);
  385.         switch (cmd)
  386.         {
  387.         case 1:
  388.             if (V3PBC_IntIsEnabled(hV3))
  389.             {
  390.                 printf ("Disabling interrupt Int\n");
  391.                 V3PBC_IntDisable(hV3);
  392.             }
  393.             else
  394.             {
  395.                 printf ("Enabling interrupts\n");
  396.                 if (!V3PBC_IntEnable(hV3, V3_IntHandlerRoutine))
  397.                     printf ("failed enabling interrupts\n");
  398.             }
  399.             break;
  400.         }
  401.     } while (cmd!=99);
  402. }
  403.  
  404. void V3_EEPROMAccess(V3PBCHANDLE hV3)
  405. {
  406.     int cmd;
  407.     DWORD addr;
  408.     BYTE device, data, readback;
  409.     DWORD dwData;
  410.  
  411.     do
  412.     {
  413.         printf ("Access the board's serial EERPOM\n");
  414.         printf ("--------------------------------\n");
  415.         printf ("1. Read byte from serial EEPROM on the board\n");
  416.         printf ("2. Write byte to the serial EEPROM on the board\n");
  417.         printf ("99. Back to main menu\n");
  418.         printf ("\n");
  419.         printf ("Enter option: ");
  420.         cmd = 0;
  421.         // force the serial boot device address to zero
  422.         device = 0;
  423.         fgets(line, sizeof(line), stdin);
  424.         sscanf (line, "%d",&cmd);
  425.         switch (cmd)
  426.         {
  427.         case 1:
  428.             printf ("Enter addr to read from (0-ff): ");
  429.             fgets(line, sizeof(line), stdin);
  430.             sscanf (line, "%x", &addr);
  431.             if (V3PBC_EEPROMRead(hV3, device, (BYTE) addr, &data))
  432.                 printf ("Value read: %x\n", data);
  433.              else
  434.                 printf("Error occured reading serial EEPROM\n");
  435.             break;
  436.  
  437.         case 2:
  438.             printf ("Enter addr to write to (0-ff): ");
  439.             fgets(line, sizeof(line), stdin);
  440.             sscanf (line, "%x", &addr);
  441.             printf ("Enter data to write: ");
  442.             fgets(line, sizeof(line), stdin);
  443.             sscanf (line, "%x",&dwData);
  444.             data = (BYTE) dwData;
  445.             if (!V3PBC_EEPROMWrite(hV3, device, (BYTE) addr, data))
  446.                 printf("Error occured reading serial EEPROM\n");
  447.  
  448.             if (V3PBC_EEPROMRead(hV3, device, (BYTE) addr, &readback))
  449.             {
  450.                 if (data != readback)
  451.                     printf ("Value readback did not match value written :  %x\n", readback);
  452.             }
  453.             else
  454.                 printf("Error occured during serial EEPROM readback\n");
  455.  
  456.             break;
  457.  
  458.         default:
  459.             break;
  460.         }
  461.     } while (cmd!=99);
  462. }
  463.  
  464. void V3_PulseLocalReset(V3PBCHANDLE hV3)
  465. {
  466.     int cmd;
  467.     WORD delay;
  468.  
  469.     do
  470.     {
  471.         printf ("Pulse the local bus reset\n");
  472.         printf ("--------------------------------\n");
  473.         printf ("1. Enter reset duration in milliseconds\n");
  474.         printf ("99. Back to main menu\n");
  475.         printf ("\n");
  476.         printf ("Enter option: ");
  477.         cmd = 0;
  478.         fgets(line, sizeof(line), stdin);
  479.         sscanf (line, "%d",&cmd);
  480.         switch (cmd)
  481.         {
  482.         case 1:
  483.             printf ("Enter delay in milliseconds: (0-65535) ");
  484.             fgets(line, sizeof(line), stdin);
  485.             sscanf (line, "%d", &delay);
  486.             V3PBC_PulseLocalReset(hV3, delay);
  487.             break;
  488.  
  489.         default:
  490.             break;
  491.         }
  492.     } while (cmd!=99);
  493. }
  494.  
  495. V3PBCHANDLE V3_LocateAndOpenBoard(DWORD dwVendorID, DWORD dwDeviceID, BOOL fUseInt)
  496. {
  497.     DWORD cards, my_card;
  498.     V3PBCHANDLE hV3 = NULL;
  499.  
  500.     if (dwVendorID==0)
  501.     {
  502.         printf ("Enter VendorID: ");
  503.         fgets(line, sizeof(line), stdin);
  504.         sscanf (line, "%x",&dwVendorID);
  505.         if (dwVendorID==0) return NULL;
  506.  
  507.         printf ("Enter DeviceID: ");
  508.         fgets(line, sizeof(line), stdin);
  509.         sscanf (line, "%x",&dwDeviceID);
  510.     }
  511.     cards = V3PBC_CountCards (dwVendorID, dwDeviceID);
  512.     if (cards==0) 
  513.     {
  514.         printf("%s", V3PBC_ErrorString);
  515.         return NULL;
  516.     }
  517.     else if (cards==1) my_card = 1;
  518.     else
  519.     {
  520.         DWORD i;
  521.  
  522.         printf("Found %d matching PCI cards\n", cards);
  523.         printf("Select card (1-%d): ", cards);
  524.         i = 0;
  525.         fgets(line, sizeof(line), stdin);
  526.         sscanf (line, "%d",&i);
  527.         if (i>=1 && i <=cards) my_card = i;
  528.         else 
  529.         {
  530.             printf ("Choice out of range\n");
  531.             return NULL;
  532.         }
  533.     }
  534.     if (V3PBC_Open (&hV3, dwVendorID, dwDeviceID, my_card - 1, fUseInt ? V3PBC_OPEN_USE_INT : 0))
  535.         printf ("V3 PBC PCI card found!\n");
  536.     else printf ("%s", V3PBC_ErrorString);
  537.     return hV3;
  538. }
  539.  
  540. int main(int argc, char *argv[])
  541. {
  542.     int cmd;
  543.     V3PBCHANDLE hV3 = NULL;
  544.     HANDLE hWD;
  545.     BOOL fUseInt = FALSE; // by default - do not install interrupts
  546.  
  547.     printf ("V3 Semiconductor PBC diagnostic utility. Version 1.0\n");
  548.     printf ("Using PBCLIB Version %d.%02d\n", V3PBCLIB_VER/100, V3PBCLIB_VER%100);
  549.     printf ("Application accesses hardware using " WD_PROD_NAME ".\n");
  550.  
  551.     // make sure WinDriver is loaded
  552.     if (!PCI_Get_WD_handle(&hWD)) return 0;
  553.     WD_Close (hWD);
  554.  
  555.     hV3 = V3_LocateAndOpenBoard(0x11b0, 0x0004, fUseInt);
  556.  
  557.     /* If board found initialize I2C bus */
  558.     if (hV3)
  559.         V3PBC_EEPROMInit(hV3);
  560.  
  561.     do
  562.     {
  563.         printf ("\n");
  564.         printf ("V3 PBC main menu\n");
  565.         printf ("-------------------\n");
  566.         printf ("1. Scan PCI bus\n");
  567.         printf ("2. Set opening board %s interrupts\n", fUseInt ? "without" : "with");
  568.         printf ("3. Locate/Choose V3 PBC board (%s interrupts)\n", fUseInt ? "with" : "without");
  569.         if (hV3)
  570.         {
  571.             printf ("4. PCI configuration registers\n");
  572.             printf ("5. V3 PBC local registers\n");
  573.             printf ("6. Access mailbox data registers on the board\n");
  574.             printf ("7. Access local address ranges on the board\n");
  575.             printf ("8. Access memory ranges on the board\n");
  576.             if (hV3->fUseInt)
  577.                 printf ("9. Enable / Disable interrupts\n");
  578.             printf ("10. Access serial EEPROM on the board\n");
  579.             printf ("11. Pulse local reset on the board\n");
  580.         }
  581.         printf ("99. Exit\n");
  582.         printf ("Enter option: ");
  583.         cmd = 0;
  584.         fgets(line, sizeof(line), stdin);
  585.         sscanf (line, "%d",&cmd);
  586.         switch (cmd)
  587.         {
  588.         case 1: // Scan PCI bus
  589.             PCI_Print_all_cards_info();
  590.             break;
  591.         case 2: // Set open board with / without interrupts
  592.             fUseInt = !fUseInt;
  593.             break;
  594.         case 3: // Locate V3 PBC board
  595.             if (hV3) V3PBC_Close(hV3);
  596.             hV3 = V3_LocateAndOpenBoard(0, 0, fUseInt);
  597.             if (!hV3) printf ("V3 PBC card open failed!\n");
  598.             break;
  599.         case 4: // PCI configuration registers
  600.             if (hV3) PCI_EditConfigReg(hV3->pciSlot);
  601.             break;
  602.         case 5: // V3 PBC local registers
  603.             if (hV3) V3_EditReg(hV3);
  604.             break;
  605.         case 6: // Access mailbox data registers on the board
  606.             if (hV3) V3_MailboxAccess(hV3);
  607.             break;
  608.         case 7: // Access local address ranges on the board
  609.             if (hV3) V3_BoardAccess(hV3);
  610.             break;
  611.         case 8: // Access memory ranges on the board
  612.             if (hV3) V3_BoardAccessSpaces(hV3);
  613.             break;
  614.         case 9: // Enable / Disable interrupts
  615.             if (hV3 && hV3->fUseInt) V3_EnableDisableInterrupts(hV3);
  616.             break;
  617.         case 10: // Access serial EEPROM on the board
  618.             if (hV3) V3_EEPROMAccess(hV3);
  619.             break;
  620.         case 11: // Reset the local bus processor
  621.             if (hV3) V3_PulseLocalReset(hV3);
  622.             break;
  623.         }
  624.     } while (cmd!=99);
  625.  
  626.     if (hV3) V3PBC_Close(hV3);
  627.  
  628.     return 0;
  629. }
  630.  
  631.                                       
  632.